package cn.bluemobi.platform.service.impl;

import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.bluemobi.common.core.dto.MapDto;
import cn.bluemobi.common.core.dto.Page;
import cn.bluemobi.common.core.dto.PageCondition;
import cn.bluemobi.platform.core.mybatis.PageUtils;
import cn.bluemobi.platform.entity.controlAudit.ControlAudit;
import cn.bluemobi.platform.entity.system.User;
import cn.bluemobi.platform.mapper.ControlAuditMapper;
import cn.bluemobi.platform.service.ControlAuditService;

/**
 * 
 * @author lvxh
 * 
 */
@Service
@Transactional
public class ControlAuditServiceImpl implements ControlAuditService {

	@Autowired
	private ControlAuditMapper controlAuditMapper;

	@Override
	public Page<Map<String, Object>> findControlAudits(PageCondition cond) {
		Page<Map<String, Object>> page = PageUtils.startPage(cond);
		page.setList(controlAuditMapper.findControlAudits(cond.getMap()));
		return page;
	}

	@Override
	public MapDto deleteControlAudit(String controlAuditId, User user) {
		MapDto dto = new MapDto();
		controlAuditMapper.deleteControlAudit(controlAuditId);
		return dto;
	}

	@Override
	public MapDto isAudit(String isAudit, String controlAuditId, User user) {
		MapDto dto = new MapDto();
		controlAuditMapper.isAudit(isAudit, controlAuditId);
		return dto;
	}

	@Override
	public ControlAudit findControlAuditDetail(String controlAuditId) {
		return controlAuditMapper.findControlAuditDetail(controlAuditId);
	}

	@Override
	public MapDto saveOrUpdate(ControlAudit controlAudit, User user) {
		MapDto dto = new MapDto();
		if (controlAuditMapper.checkIsExistVersion(controlAudit) > 0) {
			dto.errorMsg("该版本已存在");
			return dto;
		}
		if (StringUtils.isEmpty(controlAudit.getControlAuditId())) {
			controlAuditMapper.insertControlAudit(controlAudit);
		} else {
			controlAuditMapper.updateControlAudit(controlAudit);
		}
		return dto;
	}
}
